package com.briup.mt.service.impl;

import com.briup.mt.bean.Counsel;
import com.briup.mt.bean.CounselExample;
import com.briup.mt.dao.CounselMapper;
import com.briup.mt.service.IGreenHouseMessageService;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author yxy
 * @version 1.0
 * @date 2020/12/16 22:27
 */
@Service
public class GreenHouseMessageServiceImpl implements IGreenHouseMessageService {
    @Resource
    private CounselMapper counselMapper;

    @Override
    public List<Counsel> query(String status){
        CounselExample example = new CounselExample();
        if(!StringUtils.isEmpty(status)){
            example.createCriteria().andStatusLike("%" +status+ "%");
        }
        return counselMapper.selectByExample(example);
    }

    @Override
    public void saveOrUpdate(Counsel counsel){
        if (counsel.getId() == null) {
            counselMapper.insert(counsel);
        }else {
            counselMapper.updateByPrimaryKey(counsel);
        }
    }

    @Override
    public void deleteById(long id) {counselMapper.deleteByPrimaryKey(id);}
}
